package com.buyantech.smweb.json;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import cn.org.rapid_framework.page.Page;

import com.buyantech.smweb.service.AllianceManager;
import com.buyantech.smweb.vo.ResultStatusDto;
import com.buyantech.smweb.vo.query.AllianceQuery;
/**
 * 软件配置(老接口未动，只更新返回json)
 * @author liaoxin
 *
 */
@Controller
public class AppConfigJsonController {

	@Autowired
	private AllianceManager allianceManager;
//	@Autowired
//	private NoteSampleManager noteSampleManager;
//	@Autowired
//	private CompanyManager companyManager;
//	@Autowired
//	private UserManager userManager;
//	/**
//	 * 软件配置 getappsetting.json
//	 * @param userid 用户id
//	 * @param companyid 公司id
//	 * @return basePath:服务端路径 result:公司设置 approvalNote:报批范文 replyNote:审批范文  claimingNote:费用报销范文 approvalType:报批类型 productType:销量上报类型 visitType:访问类型 trackDto(track1开0关,trackWeek跟踪周期1,2,3代表周一周二周三逗号隔开):轨迹跟踪 limNumDto:各模块限制条数
//	 * {"basePath":"http://127.0.0.1:8080/SMWebPortal/","result":{"companyid":"37017456389ebd8501389ebdefe00001","company":"南天科发","settingid":"37017456389ebd8501389f00f461005b","logo":"","background":"","noticecount":100,"msgcount":100,"route":"1"},"replyNote":[{"id":3,"type":"2","note":"审核例文1111","companyid":"37017456389ebd8501389ebdefe00001"},{"id":5,"type":"2","note":"审批例文3人人","companyid":"37017456389ebd8501389ebdefe00001"}],"status":{"code":"0","desc":"查询成功"},"approvalNote":[{"id":2,"type":"1","note":"sadfasdf","companyid":"37017456389ebd8501389ebdefe00001"},{"id":6,"type":"1","note":"报批裂纹444","companyid":"37017456389ebd8501389ebdefe00001"}],"limNumDto":{"approvalNum":null,"replyNum":null,"claimingNum":null,"customerNum":null,"noteNum":null,"noticeNum":null,"productNum":null,"signinNum":null,"visitCustomerNum":null,"workReportNum":null},"trackDto":{"track":null,"trackWeek":null,"trackBeginTime":null,"trackEndTime":null},"approvalType":[{"desc":"报告类型22","companyid":"37017456389ebd8501389ebdefe00001","val":"9"},{"desc":"报告类型34","companyid":"37017456389ebd8501389ebdefe00001","val":"10"}],"claimingNote":[{"id":7,"type":"0","note":"报销事由1","companyid":"37017456389ebd8501389ebdefe00001"},{"id":8,"type":"0","note":"事由2","companyid":"37017456389ebd8501389ebdefe00001"}],"visitType":[],"productType":[{"desc":"qwer","companyid":"37017456389ebd8501389ebdefe00001","val":"1"},{"desc":"商品类型2","companyid":"37017456389ebd8501389ebdefe00001","val":"4"}]}
//	 */
//	@RequestMapping("/getappsetting")
//	public ModelAndView getappsetting(HttpServletRequest request,
//			HttpServletResponse response,@RequestParam("userid") String userid,
//			@RequestParam("companyid") String companyid) {
//		SettingQuery setq = new SettingQuery();
//		setq.setCompanyid(companyid);
//
//		Map<String, Object> modelMap = new HashMap<String, Object>();
//		ModelAndView modelView = new ModelAndView();
//		try {
//			List<Setting> settings = this.settingManager.findPage(setq)
//					.getResult();
//			if (settings == null || settings.isEmpty()) {
//				ResultStatusDto result = new ResultStatusDto("2", "未查询到数据");
//				modelMap.put("status", result);
//				modelView.addAllObjects(modelMap);
//				return modelView;
//			}
//			Setting setting = settings.get(0);
//
//			ResultStatusDto result = new ResultStatusDto("0", "查询成功");
//			modelMap.put("status", result);
//			modelMap.put("result", null);
//			
//			List<NoteSample> approvalNoteList = noteSampleManager.getApprovalNote(companyid);
//			modelMap.put("approvalNote", approvalNoteList);
//			List<NoteSample> replyNoteList = noteSampleManager.getReplyNote(companyid);
//			modelMap.put("replyNote", replyNoteList);
//			List<NoteSample> claimingNoteList = noteSampleManager.getClaimingNote(companyid);			
//			modelMap.put("claimingNote", claimingNoteList);
//			
//			
//			
//			List<NoteSample> approvalTypeList = noteSampleManager.getApprovalType(companyid);
//			List<TypeVo> approvalTypeVoList = cTypeVo(approvalTypeList);
//			modelMap.put("approvalType", approvalTypeVoList);
//			
//			
//			List<NoteSample> productTypeList = noteSampleManager.getProductType(companyid);
//			List<TypeVo> productTypeVoList = cTypeVo(productTypeList);
//			modelMap.put("productType", productTypeVoList);
//			
//			
//			List<NoteSample> visitTypeList = noteSampleManager.getVisitType(companyid);
//			List<TypeVo> visitTypeVoList = cTypeVo(visitTypeList);
//			modelMap.put("visitType", visitTypeVoList);
//			
//			
//			String path = request.getContextPath();
//			String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//			modelMap.put("basePath", basePath);
//			Company company = companyManager.getById(companyid);
//			TrackDto trackDto = new TrackDto();
//			BeanUtils.copyProperties(trackDto, company);
//			modelMap.put("trackDto", trackDto);
//
//			LimitNumDto limNumDto = new LimitNumDto();
//			BeanUtils.copyProperties(limNumDto,company);
//			modelMap.put("limNumDto", limNumDto);
//			
//			modelView.addAllObjects(modelMap);
//
//			return modelView;
//		} catch (Exception ex) {
//			ex.printStackTrace();
//			ResultStatusDto result = new ResultStatusDto("1", "查询异常");
//			modelMap.put("status", result);
//			modelView.addAllObjects(modelMap);
//			return modelView;
//		}
//
//	}
//	/**
//	 * 不对外开放，勿用！！！
//	 */
//	public void setSettingManager(SettingManager settingManager) {
//		this.settingManager = settingManager;
//	}
//	/**
//	 * 不对外开放，勿用！！！
//	 */
//	public SettingManager getSettingManager() {
//		return settingManager;
//	}
 
	@RequestMapping("/getAllianceAll")
	public ModelAndView getRouteConfig(HttpServletRequest request,
			HttpServletResponse response) {

		Map<String, Object> modelMap = new HashMap<String, Object>();
		ModelAndView modelView = new ModelAndView();
		AllianceQuery query=new AllianceQuery();
		query.setPageSize(100);
		query.setState("0");
		Page page=allianceManager.searchPage(query);
		
		ResultStatusDto result = new ResultStatusDto("0", "查询成功");
		modelMap.put("status", result);
		modelMap.put("result", page.getResult());
		modelView.addAllObjects(modelMap);
		return modelView;
	}
}
